/* Copyright 2023-2025 jobob@qq.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.flowlong.bpm.engine.core.service;

import com.flowlong.bpm.engine.ManagerService;
import com.flowlong.bpm.engine.assist.Assert;
import com.flowlong.bpm.engine.core.enums.TaskState;
import com.flowlong.bpm.engine.core.mapper.TaskDelegateMapper;
import com.flowlong.bpm.engine.entity.TaskDelegate;
import org.springframework.stereotype.Service;

/**
 * 管理服务类
 *
 * <p>
 * 尊重知识产权，CV 请保留版权，爱组搭 http://aizuda.com 出品
 * </p>
 *
 * @author hubin
 * @since 1.0
 */
@Service
public class ManagerServiceImpl implements ManagerService {
    private TaskDelegateMapper taskDelegateMapper;

    public ManagerServiceImpl(TaskDelegateMapper taskDelegateMapper) {
        this.taskDelegateMapper = taskDelegateMapper;
    }

    /**
     * 1，委托到某一个人
     * 2，委托到多个人共同决策
     */
    @Override
    public void saveOrUpdate(TaskDelegate taskDelegate) {
        Assert.notNull(taskDelegate);
        taskDelegate.setState(TaskState.active);
        if (null == taskDelegate.getId()) {
            taskDelegateMapper.insert(taskDelegate);
        } else {
            taskDelegateMapper.updateById(taskDelegate);
        }
    }

    @Override
    public void deleteSurrogate(String id) {
        TaskDelegate surrogate = getSurrogate(id);
        Assert.notNull(surrogate);
        taskDelegateMapper.deleteById(id);
    }

    @Override
    public TaskDelegate getSurrogate(String id) {
        return taskDelegateMapper.selectById(id);
    }

    @Override
    public String getSurrogate(String createBy, String processName) {
        // 待处理
        return "";
    }
}
